Completed
Pull Request — master (#77)
by Maxence
03:09
created

actions.listCirclesResult   B

Complexity

Conditions 4
Paths 4

Size

Total Lines 22

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
c 1
b 0
f 0
nc 4
nop 1
dl 0
loc 22
rs 8.9197
1
/*
2
 * Circles - Bring cloud-users closer together.
3
 *
4
 * This file is licensed under the Affero General Public License version 3 or
5
 * later. See the COPYING file.
6
 *
7
 * @author Maxence Lange <[email protected]>
8
 * @copyright 2017
9
 * @license GNU AGPL version 3 or any later version
10
 *
11
 * This program is free software: you can redistribute it and/or modify
12
 * it under the terms of the GNU Affero General Public License as
13
 * published by the Free Software Foundation, either version 3 of the
14
 * License, or (at your option) any later version.
15
 *
16
 * This program is distributed in the hope that it will be useful,
17
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19
 * GNU Affero General Public License for more details.
20
 *
21
 * You should have received a copy of the GNU Affero General Public License
22
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
23
 *
24
 */
25
26
/** global: OC */
27
/** global: OCA */
28
/** global: Notyf */
29
30
/** global: actions */
31
/** global: nav */
32
/** global: elements */
33
/** global: resultMembers */
34
/** global: resultCircles */
35
/** global: curr */
36
/** global: api */
37
38
39
var actions = {
40
41
42
	changeMemberLevel: function (member, level) {
43
		api.levelMember(curr.circle, member, level, resultMembers.levelMemberResult);
44
		nav.circlesActionReturn();
45
	},
46
47
48
	changeMemberStatus: function (member, value) {
49
		if (value === 'remove_member' || value === 'dismiss_request') {
50
			api.removeMember(curr.circle, member, resultMembers.removeMemberResult);
51
		}
52
		if (value === 'accept_request') {
53
			api.addMember(curr.circle, member, resultMembers.addMemberResult);
54
		}
55
	},
56
57
58
	selectCircle: function (circle_id) {
59
		curr.searchUser = '';
60
		elements.addMember.val('');
61
		elements.linkCircle.val('');
62
63
		nav.circlesActionReturn();
64
		api.detailsCircle(circle_id, resultCircles.selectCircleResult);
65
	},
66
67
68
	unselectCircle: function (circle_id) {
69
		elements.mainUIMembers.emptyTable();
70
		elements.navigation.children(".circle[circle-id='" + circle_id + "']").remove();
71
		elements.emptyContent.show(800);
72
		elements.mainUI.fadeOut(800);
73
74
		curr.circle = 0;
75
		curr.circleLevel = 0;
76
	},
77
78
79
	/**
80
	 *
81
	 * @param search
82
	 */
83
	searchMembersRequest: function (search) {
84
85
		if (curr.searchUser === search) {
86
			return;
87
		}
88
89
		curr.searchUser = search;
90
91
		$.get(OC.linkToOCS('apps/files_sharing/api/v1', 1) + 'sharees',
92
			{
93
				format: 'json',
94
				search: search,
95
				perPage: 200,
96
				itemType: 'principals'
97
			}, resultMembers.searchMembersResult);
98
	},
99
100
101
	getStringTypeFromType: function (type) {
102
		switch (type) {
0 ignored issues
show
Coding Style introduced by
As per coding-style, switch statements should have a default case.
Loading history...
103
			case '1':
104
				return t('circles', 'Personal circle');
105
			case '2':
106
				return t('circles', 'Hidden circle');
107
			case '4':
108
				return t('circles', 'Private circle');
109
			case '8':
110
				return t('circles', 'Public circle');
111
		}
112
113
		return t('circles', 'Circle');
114
	},
115
116
117
	/**
118
	 *
119
	 */
120
	onEventNewCircle: function () {
121
		curr.circle = 0;
122
		curr.circleLevel = 0;
123
124
		elements.circlesList.children('div').removeClass('selected');
125
		elements.emptyContent.show(800);
126
		elements.mainUI.fadeOut(800);
127
	},
128
129
130
	/**
131
	 *
132
	 */
133
	onEventNewCircleName: function () {
134
		this.onEventNewCircle();
135
		nav.displayOptionsNewCircle((elements.newName.val() !== ''));
136
	},
137
138
139
	/**
140
	 *
141
	 */
142
	onEventNewCircleType: function () {
143
		this.onEventNewCircle();
144
		elements.newTypeDefinition.children('div').fadeOut(300);
145
		var selectedType = elements.newType.children('option:selected').val();
146
		if (selectedType === '') {
147
			elements.newType.addClass('select_none');
148
		}
149
		else {
150
			elements.newType.removeClass('select_none');
151
			$('#circles_new_type_' + selectedType).fadeIn(
152
				300);
153
		}
154
	}
155
156
157
};
158